package com.szqhyxj.youxiangju.biz.entrace

import android.annotation.SuppressLint
import android.app.Activity
import android.content.Context
import android.content.SharedPreferences

object EntranceManager {

    private const val ENTRANCE = "ENTRANCE"

    private const val ROLE = "ROLE"

    private lateinit var sharedPreferences: SharedPreferences

    fun init(context: Context) {
        sharedPreferences = context.getSharedPreferences(ENTRANCE, Activity.MODE_PRIVATE)
    }

    @SuppressLint("ApplySharedPref")
    fun setToMerchant() {
        sharedPreferences.edit().putInt(ROLE, EntranceType.MERCHANT.code).commit()
    }

    @SuppressLint("ApplySharedPref")
    fun setToPartner() {
        sharedPreferences.edit().putInt(ROLE, EntranceType.PARTNER.code).commit()
    }

    fun isMerchant(): Boolean {
        val role = sharedPreferences.getInt(ROLE, EntranceType.MERCHANT.code)
        return role == EntranceType.MERCHANT.code
    }

}